package com.emep.changzhi.analyse.http.aqi;

import com.emep.changzhi.analyse.entity.aqi.AqiIactorInfo;
import com.emep.changzhi.analyse.entity.aqi.DataAqiInfo;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.aqi.AqiIactorInfoService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author xy
 * @Description: 城市排名
 * @date 2018/3/29 10:37
 * @version V1.0
 */

@RestController
@RequestMapping("ranking")
@Api(value = "airIactorController",tags = "获取城市排名信息")
public class AqiIactorInfoController {
    @Autowired
    private AqiIactorInfoService aqiIactorInfoService;
    @ApiOperation(value="获取城市排名信息", notes="获取城市排名信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "area", value = "城市code", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "city")
    public ResultBean<AqiIactorInfo> findweather(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "area");
        List<Map<String,Object>> dataAqiInfoList = new ArrayList<>();
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            dataAqiInfoList = aqiIactorInfoService.list(payload.get("area").toString());
            return result.ok(dataAqiInfoList);
        }
        return  result;
    }
}
